<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <script src="./lib/vue.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
        <title>07 vue-fetch-axios</title>
    </head>
    <body>
        <div id="app">
            <button @click="handleClickFetch()">fetch获取影片数据</button>
            <button @click="handleClickAxios()">axios获取影片数据</button>
            <ul>
                <li v-for="(data, index) in dataList">
                    <h2>{{ data.name }}</h2>
                    <img :src="data.poster" />
                </li>
            </ul>
        </div>

        <script>
            const vm = new Vue({
                el: '#app',
                data() {
                    return {
                        dataList: []
                    };
                },
                methods: {
                    handleClickFetch() {
                        fetch('./json/test.json')
                            .then((res) => res.json())
                            .then((res) => {
                                this.dataList = res.data.films;
                            });
                    },
                    handleClickAxios() {
                        axios
                            .get('./json/test.json')
                            .then((res) => {
                                this.dataList = res.data.data.films;
                            })
                            .catch((err) => {
                                console.log(err);
                            });
                    }
                }
            });
        </script>
    </body>
</html>
